﻿var username,secretkey;
var isjump = 0;//控制翻页
var layer,$,laydate,upload,element,form,loadmsg,kj_id;
var Prize_img;	//商城分享LOGO
layui.config({

}).use(['form','laydate', 'layer', 'element','upload'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
   // laydate = layui.laydate;//日期
    upload = layui.upload;//上传
    element = layui.element; //元素操作
	username = $.session.get("username");
	secretkey = $.session.get("user_secretkey");
	note_demo();
	//上传奖品图片
    var uploadInst = upload.render({
		elem: '#uploadimgs'
		,url: '../../../../UploadServlet?serialtype=advimg'
		,size: 150
		,before: function(obj){
		  //预读本地文件示例，不支持ie8
		  obj.preview(function(index, file, result){
			$("#Prize_img").css("display","block");
			$('#preview').attr('src', result); //图片链接（base64）

		  });
		}
		,done: function(res){
			console.log("res====="+JSON.stringify(res));
		  //如果上传失败
		  if(res.code > 0){
			return layer.msg('上传失败');
		  }
		  Prize_img = res.data[0].src;
		}
		,error: function(){
		  //演示失败状态，并实现重传
			var demoText = $('#demoText');
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn  demo-reload">重试</a>');
			demoText.find('.demo-reload').on('click', function(){
			uploadInst.upload();
		  });
		}
	 });

});

function note_demo(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");
	$.ajax({
		url: "../../../../service",
		cache : false,
		data : {
			proc : "g_xmy.find_basis_set",
			para : "['" + username + "','" + secretkey + "']"
		},
		dataType : "json",
		success : function(data) {
			if (data[0].TAG == "0") {
				window.location.href="./error.html";
			} else {
				document.getElementById("share_title").value = data[0].SHOPPINGSHARE_TITLE;
				document.getElementById("share_miaosu").value = data[0].SHOPPINGSHARE_DESCRIBE;
				Prize_img = data[0].SHOPPINGSHARE_LOGO;
				if(Prize_img!=''&&Prize_img!=null){
					$("#Prize_img").css("display","block");
					$('#preview').attr('src', '../../../../advimg/'+Prize_img); //图片链接（base64）
				}else{
					$("#prize_picture").hide();
					$('#preview').css("display","block");
				}
			}
		}
	});
}


function update_forwarding(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");
	var share_title = document.getElementById("share_title").value;
	var share_miaosu = document.getElementById("share_miaosu").value;
	$.ajax({
		url: "../../../../service",
		cache : false,
		data : {
			proc : "g_xmy.update_basis_set",
			para : "['" + username + "','" + secretkey + "','" + share_title + "','" + share_miaosu + "','" + Prize_img + "']"
		},
		dataType : "json",
		success : function(data) {
			if (data[0].TAG == "1") {
				layer.alert(data[0].MSG,function(index){
					 window.location.href="./basis_set.html";
					 layer.close(index);
				});
			} else {
				layer.alert("保存失败");
			}
		}
	});
}


